﻿using Microsoft.CSharp.Activities;
using System;
using System.Activities;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WFExtended.Twitter.Activities.Designers;

namespace WFExtended.Twitter.Activities
{
    /// <summary>
    /// Updates the authenticating user's current status, also known as tweeting.
    /// </summary>
    [ToolboxBitmapAttribute(typeof(EntryPoint), "Resources.TweetsToolbox.bmp")]
    [Designer(typeof(SendTweetDesigner))]
    [Description("Updates the authenticating user's current status, also known as tweeting.")]
    public class SendTweet : TwitterOperationInvoker<Status>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SendTweet"/> class.
        /// </summary>
        public SendTweet()
            : base("SendTweet")
        {
            DisplayCoordinates = new InArgument<bool>(new CSharpValue<bool>("true"));
            TrimUser = new InArgument<bool>(new CSharpValue<bool>("false"));
        }


        /// <summary>
        /// The text of your status update, typically up to 140 characters. 
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        /// The text of your status update
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("The text of your status update")]
        [RequiredArgument]
        public InArgument<string> Text { get; set; }

        /// <summary>
        /// The ID of an existing status that the update is in reply to.
        /// </summary>
        /// <value>
        /// The ID of an existing status that the update is in reply to.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("The ID of an existing status that the update is in reply to.")]
        public InArgument<string> InReplyToStatusID { get; set; }

        /// <summary>
        /// The latitude of the location this tweet refers to.
        /// </summary>
        /// <value>
        /// The latitude.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("The latitude of the location this tweet refers to.")]
        public InArgument<string> Latitude { get; set; }

        /// <summary>
        /// The longitude of the location this tweet refers to.
        /// </summary>
        /// <value>
        /// The longitude.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("The longitude of the location this tweet refers to.")]
        public InArgument<string> Longitude { get; set; }

        /// <summary>
        /// A place in the world. These IDs can be retrieved from ReverseGeoCode.
        /// </summary>
        /// <value>
        /// The place ID.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("A place in the world. These IDs can be retrieved from ReverseGeoCode.")]
        public InArgument<string> PlaceID { get; set; }

        /// <summary>
        /// Whether or not to put a pin on the exact coordinates a tweet has been sent from.
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        /// The display coordinates.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("Whether or not to put a pin on the exact coordinates a tweet has been sent from.")]
        [RequiredArgument]
        public InArgument<bool> DisplayCoordinates { get; set; }

        /// <summary>
        ///  When set to either true, each tweet returned in a timeline will include a user object including only the status authors numerical ID.
        ///  <remarks>Required Argument</remarks>
        /// </summary>
        /// <value>
        ///   <c>true</c> if [trim user]; otherwise, <c>false</c>.
        /// </value>
        [Browsable(true)]
        [Category("Parameters")]
        [Description("Trim User")]
        [RequiredArgument]
        public InArgument<bool> TrimUser { get; set; }

        /// <summary>
        /// Caches the metadata.
        /// </summary>
        /// <param name="metadata">The metadata.</param>
        protected override void CacheMetadata(System.Activities.NativeActivityMetadata metadata)
        {
            RuntimeArgument textArgument = new RuntimeArgument("Text", typeof(string), ArgumentDirection.In, true);
            metadata.Bind(Text, textArgument);
            metadata.AddArgument(textArgument);

            RuntimeArgument inReplyToStatusIDArgument = new RuntimeArgument("InReplyToStatusID", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(InReplyToStatusID, inReplyToStatusIDArgument);
            metadata.AddArgument(inReplyToStatusIDArgument);

            RuntimeArgument latitudeArgument = new RuntimeArgument("Latitude", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(Latitude, latitudeArgument);
            metadata.AddArgument(latitudeArgument);

            RuntimeArgument longitudeArgument = new RuntimeArgument("Longitude", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(Longitude, longitudeArgument);
            metadata.AddArgument(longitudeArgument);

            RuntimeArgument placeIDArgument = new RuntimeArgument("PlaceID", typeof(string), ArgumentDirection.In, false);
            metadata.Bind(PlaceID, placeIDArgument);
            metadata.AddArgument(placeIDArgument);

            RuntimeArgument displayCoordinatesArgument = new RuntimeArgument("DisplayCoordinates", typeof(bool), ArgumentDirection.In, true);
            metadata.Bind(DisplayCoordinates, displayCoordinatesArgument);
            metadata.AddArgument(displayCoordinatesArgument);

            RuntimeArgument trimUserArgument = new RuntimeArgument("TrimUser", typeof(bool), ArgumentDirection.In, true);
            metadata.Bind(TrimUser, trimUserArgument);
            metadata.AddArgument(trimUserArgument);

            base.CacheMetadata(metadata);
        }

        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        protected override void Execute(System.Activities.NativeActivityContext context)
        {
            Parameters.Clear();

            Parameters.Add("text", Text);
            Parameters.Add("inReplyToStatusID", InReplyToStatusID);
            Parameters.Add("latitude", Latitude);
            Parameters.Add("longitude", Longitude);
            Parameters.Add("placeID", PlaceID);
            Parameters.Add("displayCoordinates", DisplayCoordinates);
            Parameters.Add("trimUser", TrimUser);

            base.Execute(context);
        }
    }
}
